
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>GenStage · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="protocols.html" />
    
    
    <link rel="prev" href="behaviours.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">第一部分：基础</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../basics/basics.html">
            
                <a href="../basics/basics.html">
            
                    
                    基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../basics/collections.html">
            
                <a href="../basics/collections.html">
            
                    
                    集合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../basics/enum.html">
            
                <a href="../basics/enum.html">
            
                    
                    Enum 模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../basics/pattern-matching.html">
            
                <a href="../basics/pattern-matching.html">
            
                    
                    模式匹配
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../basics/control-structures.html">
            
                <a href="../basics/control-structures.html">
            
                    
                    控制语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../basics/functions.html">
            
                <a href="../basics/functions.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../basics/pipe-operator.html">
            
                <a href="../basics/pipe-operator.html">
            
                    
                    管道操作符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../basics/modules.html">
            
                <a href="../basics/modules.html">
            
                    
                    模块(Module)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../basics/mix.html">
            
                <a href="../basics/mix.html">
            
                    
                    Mix
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../basics/sigils.html">
            
                <a href="../basics/sigils.html">
            
                    
                    魔符(Sigil)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../basics/documentation.html">
            
                <a href="../basics/documentation.html">
            
                    
                    文档模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../basics/testing.html">
            
                <a href="../basics/testing.html">
            
                    
                    测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../basics/comprehensions.html">
            
                <a href="../basics/comprehensions.html">
            
                    
                    推导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../basics/strings.html">
            
                <a href="../basics/strings.html">
            
                    
                    字符串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="../basics/date-time.html">
            
                <a href="../basics/date-time.html">
            
                    
                    日期和时间
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="../basics/mix-tasks.html">
            
                <a href="../basics/mix-tasks.html">
            
                    
                    自定义Mix任务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="../basics/iex-helpers.html">
            
                <a href="../basics/iex-helpers.html">
            
                    
                    IEx辅助函数
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第二部分：高级</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="erlang.html">
            
                <a href="erlang.html">
            
                    
                    和Erlang互操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="error-handling.html">
            
                <a href="error-handling.html">
            
                    
                    错误处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="escripts.html">
            
                <a href="escripts.html">
            
                    
                    可执行文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="concurrency.html">
            
                <a href="concurrency.html">
            
                    
                    并发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="otp-concurrency.html">
            
                <a href="otp-concurrency.html">
            
                    
                    OTP并发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="otp-supervisors.html">
            
                <a href="otp-supervisors.html">
            
                    
                    OTP Supervisors
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="otp-distribution.html">
            
                <a href="otp-distribution.html">
            
                    
                    OTP 分布式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="metaprogramming.html">
            
                <a href="metaprogramming.html">
            
                    
                    元编程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="umbrella-projects.html">
            
                <a href="umbrella-projects.html">
            
                    
                    Umbrella Projects
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.10" data-path="typespec.html">
            
                <a href="typespec.html">
            
                    
                    Specifications and types
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.11" data-path="behaviours.html">
            
                <a href="behaviours.html">
            
                    
                    行为
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="2.12" data-path="gen-stage.html">
            
                <a href="gen-stage.html">
            
                    
                    GenStage
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.13" data-path="protocols.html">
            
                <a href="protocols.html">
            
                    
                    协议
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.14" data-path="nerves.html">
            
                <a href="nerves.html">
            
                    
                    Nerves
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第三部分：ECTO</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../ecto/basics.html">
            
                <a href="../ecto/basics.html">
            
                    
                    Basics
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../ecto/changesets.html">
            
                <a href="../ecto/changesets.html">
            
                    
                    Changesets
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../ecto/associations.html">
            
                <a href="../ecto/associations.html">
            
                    
                    关联关系
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="../ecto/querying.html">
            
                <a href="../ecto/querying.html">
            
                    
                    查询
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第四部分：专题</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../specifics/plug.html">
            
                <a href="../specifics/plug.html">
            
                    
                    Plug
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="../specifics/eex.html">
            
                <a href="../specifics/eex.html">
            
                    
                    嵌入的 Elixir(EEx)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="../specifics/ets.html">
            
                <a href="../specifics/ets.html">
            
                    
                    Erlang 项式存储(ETS)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="../specifics/mnesia.html">
            
                <a href="../specifics/mnesia.html">
            
                    
                    Mnesia 数据库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="../specifics/debugging.html">
            
                <a href="../specifics/debugging.html">
            
                    
                    调试
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第五部分：程序库</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../libraries/guardian.html">
            
                <a href="../libraries/guardian.html">
            
                    
                    Guardian(基础)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="../libraries/poolboy.html">
            
                <a href="../libraries/poolboy.html">
            
                    
                    Poolboy
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="../libraries/benchee.html">
            
                <a href="../libraries/benchee.html">
            
                    
                    Benchee
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="../libraries/bypass.html">
            
                <a href="../libraries/bypass.html">
            
                    
                    Bypass
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="../libraries/distillery.html">
            
                <a href="../libraries/distillery.html">
            
                    
                    Distillery(基础)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="../libraries/stream-data.html">
            
                <a href="../libraries/stream-data.html">
            
                    
                    StreamData
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >GenStage</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <p>&#x672C;&#x8BFE;, &#x6211;&#x4EEC;&#x5C06;&#x5B66;&#x4E60; GenStage, &#x5B83;&#x7684;&#x4F5C;&#x7528;, &#x4EE5;&#x53CA;&#x5982;&#x4F55;&#x5728;&#x6211;&#x4EEC;&#x7684;&#x5E94;&#x7528;&#x4E2D;&#x4F7F;&#x7528;&#x5B83;.</p>
<h2 id="&#x4ECB;&#x7ECD;">&#x4ECB;&#x7ECD;</h2>
<p>&#x90A3;&#x4E48;&#x4EC0;&#x4E48;&#x662F; GenStage? &#x5B98;&#x65B9;&#x6587;&#x6863;&#x4E2D;&#x5199;&#x9053;, &#x5B83;&#x662F;&quot;Elixir &#x7684;&#x89C4;&#x683C;&#x4E0E;&#x8BA1;&#x7B97;&#x6D41;&#x7A0B;&quot;, &#x4F46;&#x5BF9;&#x6211;&#x4EEC;&#x6765;&#x8BF4;&#x610F;&#x5473;&#x7740;&#x4EC0;&#x4E48;?</p>
<p>&#x8FD9;&#x610F;&#x5473;&#x7740;, GenStage &#x4E3A;&#x6211;&#x4EEC;&#x63D0;&#x4F9B;&#x4E86;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x7BA1;&#x9053;&#x64CD;&#x4F5C;&#x7684;&#x65B9;&#x5F0F;, &#x5B83;&#x662F;&#x7531;&#x591A;&#x4E2A;&#x72EC;&#x7ACB;&#x7684;&#x9636;&#x6BB5;(&#x6216; stage)&#x7EC4;&#x5408;&#x8D77;&#x6765;&#x7684;; &#x5982;&#x679C;&#x4F60;&#x4E4B;&#x524D;&#x4F7F;&#x7528;&#x8FC7;&#x7BA1;&#x9053;, &#x5E94;&#x8BE5;&#x719F;&#x6089;&#x5176;&#x4E2D;&#x7684;&#x4E00;&#x4E9B;&#x6982;&#x5FF5;.</p>
<p>&#x4E3A;&#x4E86;&#x66F4;&#x597D;&#x5730;&#x7406;&#x89E3;&#x5B83;&#x7684;&#x5DE5;&#x4F5C;&#x539F;&#x7406;, &#x8BA9;&#x6211;&#x4EEC;&#x6765;&#x770B;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x751F;&#x4EA7;&#x8005;-&#x6D88;&#x8D39;&#x8005;&#x6D41;&#x7A0B;:</p>
<pre><code>[A] -&gt; [B] -&gt; [C]
</code></pre><p>&#x5728;&#x8FD9;&#x4E2A;&#x4F8B;&#x5B50;&#x91CC;, &#x6211;&#x4EEC;&#x6709;&#x4E09;&#x4E2A; stage: &#x4E00;&#x4E2A;&#x751F;&#x4EA7;&#x8005; <code>A</code>, &#x4E00;&#x4E2A;&#x751F;&#x4EA7;&#x8005;-&#x6D88;&#x8D39;&#x8005; <code>B</code>, &#x4EE5;&#x53CA;&#x4E00;&#x4E2A;&#x6D88;&#x8D39;&#x8005; <code>C</code>.  <code>A</code> &#x751F;&#x4EA7;&#x4E00;&#x4E2A; <code>B</code> &#x4F9B;&#x6D88;&#x8D39;&#x7684;&#x503C;, <code>B</code> &#x6267;&#x884C;&#x4E86;&#x4E00;&#x4E9B;&#x5DE5;&#x4F5C;&#x5E76;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x503C;, &#x63D0;&#x4F9B;&#x7ED9;&#x6D88;&#x8D39;&#x8005; <code>C</code>; &#x6211;&#x4EEC;&#x5C06;&#x5728;&#x4E0B;&#x4E00;&#x8282;&#x4E2D;&#x770B;&#x5230;&#x8FD9;&#x4E9B;&#x89D2;&#x8272;, &#x5B83;&#x4EEC;&#x5341;&#x5206;&#x91CD;&#x8981;.</p>
<p>&#x867D;&#x7136;&#x6211;&#x4EEC;&#x7684;&#x4F8B;&#x5B50;&#x662F;1&#x5BF9;1&#x7684;&#x751F;&#x4EA7;&#x8005;&#x548C;&#x6D88;&#x8D39;&#x8005;, &#x4F46;&#x662F;&#x5728;&#x4EFB;&#x4F55;&#x4E00;&#x4E2A; stage &#x90FD;&#x53EF;&#x80FD;&#x62E5;&#x6709;&#x591A;&#x4E2A;&#x751F;&#x4EA7;&#x8005;&#x548C;&#x591A;&#x4E2A;&#x6D88;&#x8D39;&#x8005;.</p>
<p>&#x4E3A;&#x4E86;&#x66F4;&#x597D;&#x5730;&#x8BF4;&#x660E;&#x8FD9;&#x4E9B;&#x6982;&#x5FF5;, &#x6211;&#x4EEC;&#x5C06;&#x4F7F;&#x7528; GenStage &#x6765;&#x6784;&#x5EFA;&#x7BA1;&#x9053;, &#x4F46;&#x9996;&#x5148;&#x8BA9;&#x6211;&#x4EEC;&#x6765;&#x63A2;&#x8BA8;&#x4E00;&#x4E0B; GenStage &#x7684;&#x89D2;&#x8272;.</p>
<h2 id="&#x6D88;&#x8D39;&#x8005;&#x4E0E;&#x751F;&#x4EA7;&#x8005;">&#x6D88;&#x8D39;&#x8005;&#x4E0E;&#x751F;&#x4EA7;&#x8005;</h2>
<p>&#x6B63;&#x5982;&#x6211;&#x4EEC;&#x6240;&#x770B;&#x5230;&#x7684;, &#x6211;&#x4EEC;&#x8D4B;&#x4E88; stage &#x7684;&#x89D2;&#x8272;&#x5F88;&#x91CD;&#x8981;. GenStage &#x7684;&#x89C4;&#x8303;&#x4E2D;&#x627F;&#x8BA4;&#x4E09;&#x79CD;&#x89D2;&#x8272;:</p>
<ul>
<li><p><code>:producer</code> &#x2014; &#x4E00;&#x4E2A;&#x6E90;.  &#x751F;&#x4EA7;&#x8005;&#x7B49;&#x5F85;&#x6D88;&#x8D39;&#x8005;&#x7684;&#x9700;&#x6C42;&#x5E76;&#x54CD;&#x5E94;&#x6D88;&#x8D39;&#x8005;&#x7684;&#x9700;&#x6C42;.</p>
</li>
<li><p><code>:producer_consumer</code> &#x2014; &#x65E2;&#x662F;&#x6E90;&#x4E5F;&#x662F;&#x6C47;.  &#x751F;&#x4EA7;&#x8005;-&#x6D88;&#x8D39;&#x8005; &#x53EF;&#x4EE5;&#x54CD;&#x5E94;&#x5176;&#x4ED6;&#x6D88;&#x8D39;&#x8005;&#x7684;&#x9700;&#x6C42;, &#x5E76;&#x5411;&#x5176;&#x4ED6;&#x751F;&#x4EA7;&#x8005;&#x63D0;&#x51FA;&#x9700;&#x6C42;.</p>
</li>
<li><p><code>:consumer</code> &#x2014; &#x4E00;&#x4E2A;&#x6C47;.  &#x6D88;&#x8D39;&#x8005;&#x4ECE;&#x5176;&#x4ED6;&#x751F;&#x4EA7;&#x8005;&#x5904;&#x8BF7;&#x6C42;&#x5E76;&#x63A5;&#x6536;&#x6570;&#x636E;.</p>
</li>
</ul>
<p>&#x6CE8;&#x610F;&#x5230;&#x6211;&#x4EEC;&#x7684;&#x751F;&#x4EA7;&#x8005;&#x662F;&#x5728; <strong>&#x7B49;&#x5F85;</strong> &#x9700;&#x6C42;&#x4E86;&#x5417;?  &#x4F7F;&#x7528; GenStage, &#x6211;&#x4EEC;&#x7684;&#x6D88;&#x8D39;&#x8005;&#x5411;&#x4E0A;&#x6E38;&#x53D1;&#x9001;&#x9700;&#x6C42;, &#x5E76;&#x5904;&#x7406;&#x6765;&#x81EA;&#x751F;&#x4EA7;&#x8005;&#x7684;&#x6570;&#x636E;. &#x8FD9;&#x6709;&#x52A9;&#x4E8E;&#x79F0;&#x4E3A;&#x80CC;&#x538B;&#x7684;&#x673A;&#x5236;.  &#x5F53;&#x6D88;&#x8D39;&#x8005;&#x5FD9;&#x788C;&#x65F6;, &#x80CC;&#x538B;&#x4F7F;&#x5F97;&#x751F;&#x4EA7;&#x8005;&#x5728;&#x6D88;&#x8D39;&#x8005;&#x7E41;&#x5FD9;&#x65F6;&#x4E0D;&#x4F1A;&#x627F;&#x53D7;&#x8FC7;&#x5EA6;&#x7684;&#x538B;&#x529B;.</p>
<p>&#x73B0;&#x5728;, &#x6211;&#x4EEC;&#x5DF2;&#x7ECF;&#x4ECB;&#x7ECD;&#x4E86; GenStage &#x4E2D;&#x7684;&#x89D2;&#x8272;, &#x8BA9;&#x6211;&#x4EEC;&#x5F00;&#x59CB;&#x7F16;&#x5199;&#x7684;&#x5E94;&#x7528;.</p>
<h2 id="&#x5165;&#x95E8;">&#x5165;&#x95E8;</h2>
<p>&#x5728;&#x8FD9;&#x4E2A;&#x4F8B;&#x5B50;&#x4E2D;, &#x6211;&#x4EEC;&#x5C06;&#x6784;&#x5EFA;&#x4E00;&#x4E2A; GenStage &#x5E94;&#x7528;, &#x5B83;&#x5C06;&#x4EA7;&#x751F;&#x6570;&#x5B57;, &#x8FC7;&#x6EE4;&#x6389;&#x5076;&#x6570;, &#x6700;&#x540E;&#x6253;&#x5370;&#x51FA;&#x5269;&#x4E0B;&#x7684;&#x6570;&#x5B57;.</p>
<p>&#x5728;&#x8FD9;&#x4E2A;&#x5E94;&#x7528;&#x4E2D;&#x6211;&#x4EEC;&#x5C06;&#x7528;&#x5230;&#x5168;&#x90E8;&#x4E09;&#x79CD;&#x89D2;&#x8272;.  &#x6211;&#x4EEC;&#x7684;&#x751F;&#x4EA7;&#x8005;&#x5C06;&#x8D1F;&#x8D23;&#x8BA1;&#x6570;&#x548C;&#x6392;&#x653E;&#x6570;&#x5B57;.  &#x6211;&#x4EEC;&#x5C06;&#x4F7F;&#x7528;&#x4E00;&#x4E2A;&#x751F;&#x4EA7;&#x8005;-&#x6D88;&#x8D39;&#x8005;&#x6765;&#x7B5B;&#x9009;&#x5076;&#x6570;, &#x5E76;&#x54CD;&#x5E94;&#x6765;&#x81EA;&#x4E0B;&#x6E38;&#x7684;&#x9700;&#x6C42;.  &#x6700;&#x540E;, &#x6211;&#x4EEC;&#x5C06;&#x6784;&#x5EFA;&#x4E00;&#x4E2A;&#x6D88;&#x8D39;&#x8005;&#x6765;&#x663E;&#x793A;&#x6211;&#x4EEC;&#x5269;&#x4E0B;&#x7684;&#x6570;&#x5B57;.</p>
<p>&#x9996;&#x5148;, &#x6211;&#x4EEC;&#x751F;&#x6210;&#x4E00;&#x4E2A;&#x5E26;&#x6709;&#x76D1;&#x63A7;&#x6811;&#x7684;&#x9879;&#x76EE;:</p>
<pre><code class="lang-shell">$ mix new genstage_example --sup
$ cd genstage_example
</code></pre>
<p>&#x8BA9;&#x6211;&#x4EEC;&#x5728; <code>mix.exs</code> &#x6587;&#x4EF6;&#x7684;&#x4F9D;&#x8D56;&#x5217;&#x8868;&#x4E2D;&#x52A0;&#x5165; <code>gen_stage</code>:</p>
<pre><code class="lang-elixir"><span class="hljs-function"><span class="hljs-keyword">defp</span> <span class="hljs-title">deps</span></span> <span class="hljs-keyword">do</span>
  [
    {<span class="hljs-symbol">:gen_stage</span>, <span class="hljs-string">&quot;~&gt; 0.11&quot;</span>},
  ]
<span class="hljs-keyword">end</span>
</code></pre>
<p>&#x63A5;&#x7740;&#x83B7;&#x53D6;&#x5E76;&#x7F16;&#x8BD1;&#x4F9D;&#x8D56;:</p>
<pre><code class="lang-shell">$ mix do deps.get, compile
</code></pre>
<p>&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x51C6;&#x5907;&#x597D;&#x7F16;&#x5199;&#x6211;&#x4EEC;&#x7684;&#x751F;&#x4EA7;&#x8005;&#x4E86;!</p>
<h2 id="&#x751F;&#x4EA7;&#x8005;">&#x751F;&#x4EA7;&#x8005;</h2>
<p>GenStage &#x5E94;&#x7528;&#x7684;&#x7B2C;&#x4E00;&#x6B65;&#x662F;&#x521B;&#x5EFA;&#x6211;&#x4EEC;&#x7684;&#x751F;&#x4EA7;&#x8005;.  &#x6B63;&#x5982;&#x6211;&#x4EEC;&#x4E4B;&#x524D;&#x8BA8;&#x8BBA;&#x8FC7;&#x7684;, &#x6211;&#x4EEC;&#x60F3;&#x8981;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x53D1;&#x51FA;&#x6052;&#x5B9A;&#x6570;&#x5B57;&#x6D41;&#x7684;&#x751F;&#x4EA7;&#x8005;.  &#x8BA9;&#x6211;&#x4EEC;&#x6765;&#x521B;&#x5EFA;&#x751F;&#x4EA7;&#x8005;&#x7684;&#x6587;&#x4EF6;:</p>
<pre><code class="lang-shell">$ mkdir lib/genstage_example
$ touch lib/genstage_example/producer.ex
</code></pre>
<p>&#x73B0;&#x5728;&#x6DFB;&#x52A0;&#x4EE3;&#x7801;:</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">GenstageExample</span></span>.Producer <span class="hljs-keyword">do</span>
  <span class="hljs-keyword">use</span> GenStage

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">start_link</span></span>(initial \\ <span class="hljs-number">0</span>) <span class="hljs-keyword">do</span>
    GenStage.start_link(__MODULE_<span class="hljs-number">_</span>, initial, <span class="hljs-symbol">name:</span> __MODULE_<span class="hljs-number">_</span>)
  <span class="hljs-keyword">end</span>

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">init</span></span>(counter), <span class="hljs-symbol">do:</span> {<span class="hljs-symbol">:producer</span>, counter}

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">handle_demand</span></span>(demand, state) <span class="hljs-keyword">do</span>
    events = Enum.to_list(state..(state + demand - <span class="hljs-number">1</span>))
    {<span class="hljs-symbol">:noreply</span>, events, state + demand}
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<p>&#x8FD9;&#x91CC;&#x6709;&#x4E24;&#x4E2A;&#x91CD;&#x8981;&#x7684;&#x90E8;&#x5206;&#x9700;&#x8981;&#x6CE8;&#x610F;, <code>init/1</code> &#x548C; <code>handle_demand/2</code>.  &#x5728; <code>init/1</code> &#x4E2D;&#x6211;&#x4EEC;&#x50CF; GenServer &#x4E00;&#x6837;&#x8BBE;&#x7F6E;&#x4E86;&#x7684;&#x521D;&#x59CB;&#x72B6;&#x6001;, &#x66F4;&#x91CD;&#x8981;&#x7684;&#x662F;&#x6211;&#x4EEC;&#x5C06;&#x5176;&#x6807;&#x6CE8;&#x4E3A;&#x4E86;&#x4E00;&#x4E2A;&#x751F;&#x4EA7;&#x8005;.  GenStage &#x6839;&#x636E; <code>init/1</code> &#x51FD;&#x6570;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#x6765;&#x533A;&#x5206;&#x8FDB;&#x7A0B;&#x7684;&#x7C7B;&#x578B;.</p>
<p><code>handle_demand/2</code> &#x51FD;&#x6570;&#x662F;&#x751F;&#x4EA7;&#x8005;&#x7684;&#x4E3B;&#x8981;&#x90E8;&#x5206;, &#x4E5F;&#x662F;&#x6240;&#x6709; GenStage &#x751F;&#x4EA7;&#x8005;&#x90FD;&#x5FC5;&#x987B;&#x5B9E;&#x73B0;&#x7684;.  &#x8FD9;&#x91CC;, &#x6211;&#x4EEC;&#x8FD4;&#x56DE;&#x4E86;&#x6D88;&#x8D39;&#x8005;&#x6240;&#x9700;&#x8981;&#x7684;&#x6570;&#x5B57;, &#x5E76;&#x589E;&#x52A0;&#x4E86;&#x8BA1;&#x6570;.  &#x6D88;&#x8D39;&#x8005;&#x53D1;&#x6765;&#x7684;&#x9700;&#x6C42;, &#x4E5F;&#x5C31;&#x662F;&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#x7684;<code>demand</code>, &#x662F;&#x4E00;&#x4E2A;&#x4EE3;&#x8868;&#x5176;&#x6240;&#x80FD;&#x5904;&#x7406;&#x7684;&#x4E8B;&#x4EF6;&#x6570;&#x91CF;&#x7684;&#x6574;&#x6570;; &#x9ED8;&#x8BA4;&#x503C;&#x662F; 1000.</p>
<h2 id="&#x751F;&#x4EA7;&#x8005;-&#x6D88;&#x8D39;&#x8005;">&#x751F;&#x4EA7;&#x8005;-&#x6D88;&#x8D39;&#x8005;</h2>
<p>&#x73B0;&#x5728;, &#x6211;&#x4EEC;&#x6709;&#x4E86;&#x4E00;&#x4E2A;&#x4EA7;&#x751F;&#x6570;&#x5B57;&#x7684;&#x751F;&#x4EA7;&#x8005;, &#x8BA9;&#x6211;&#x4EEC;&#x770B;&#x770B;&#x751F;&#x4EA7;&#x8005;-&#x6D88;&#x8D39;&#x8005;.  &#x6211;&#x4EEC;&#x60F3;&#x8981;&#x5411;&#x751F;&#x4EA7;&#x8005;&#x8BF7;&#x6C42;&#x6570;&#x5B57;, &#x8FC7;&#x6EE4;&#x6389;&#x5947;&#x6570;, &#x5E76;&#x54CD;&#x5E94;&#x9700;&#x6C42;.</p>
<pre><code class="lang-shell">$ touch lib/genstage_example/producer_consumer.ex
</code></pre>
<p>&#x8BA9;&#x6211;&#x4EEC;&#x5728;&#x6587;&#x4EF6;&#x4E2D;&#x5199;&#x5165;&#x5982;&#x4E0B;&#x4EE3;&#x7801;:</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">GenstageExample</span></span>.ProducerConsumer <span class="hljs-keyword">do</span>
  <span class="hljs-keyword">use</span> GenStage

  require Integer

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">start_link</span></span> <span class="hljs-keyword">do</span>
    GenStage.start_link(__MODULE_<span class="hljs-number">_</span>, <span class="hljs-symbol">:state_doesnt_matter</span>, <span class="hljs-symbol">name:</span> __MODULE_<span class="hljs-number">_</span>)
  <span class="hljs-keyword">end</span>

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">init</span></span>(state) <span class="hljs-keyword">do</span>
    {<span class="hljs-symbol">:producer_consumer</span>, state, <span class="hljs-symbol">subscribe_to:</span> [GenstageExample.Producer]}
  <span class="hljs-keyword">end</span>

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">handle_events</span></span>(events, _from, state) <span class="hljs-keyword">do</span>
    numbers =
      events
      |&gt; Enum.filter(&amp;Integer.is_even/<span class="hljs-number">1</span>)

    {<span class="hljs-symbol">:noreply</span>, numbers, state}
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<p>&#x4F60;&#x53EF;&#x80FD;&#x5DF2;&#x7ECF;&#x6CE8;&#x610F;&#x5230;, &#x6211;&#x4EEC;&#x5728;&#x751F;&#x4EA7;&#x8005;-&#x6D88;&#x8D39;&#x8005;&#x4E2D;, &#x4E3A; <code>init/1</code> &#x589E;&#x52A0;&#x4E86;&#x4E00;&#x4E2A;&#x9009;&#x9879;, &#x8FD8;&#x589E;&#x52A0;&#x4E86;&#x4E00;&#x4E2A;&#x51FD;&#x6570;: <code>handle_events/3</code>.  &#x901A;&#x8FC7; <code>subscribe_to</code> &#x9009;&#x9879;, &#x6211;&#x4EEC;&#x8BA9; GenStage &#x4E0E;&#x6307;&#x5B9A;&#x7684;&#x751F;&#x4EA7;&#x8005;&#x8FDB;&#x884C;&#x901A;&#x4FE1;.</p>
<p><code>handle_events/3</code> &#x51FD;&#x6570;&#x662F;&#x6211;&#x4EEC;&#x7684;&#x4E3B;&#x529B;, &#x5B83;&#x63A5;&#x6536;&#x4E8B;&#x4EF6;, &#x5904;&#x7406;&#x5B83;&#x4EEC;, &#x5E76;&#x5F97;&#x5230;&#x8F6C;&#x6362;&#x540E;&#x7684;&#x96C6;&#x5408;.  &#x6211;&#x4EEC;&#x5C06;&#x5728;&#x6D88;&#x8D39;&#x8005;&#x4E2D;&#x770B;&#x5230;&#x975E;&#x5E38;&#x7C7B;&#x4F3C;&#x7684;&#x5B9E;&#x73B0;, &#x4F46;&#x662F;&#x6700;&#x91CD;&#x8981;&#x7684;&#x533A;&#x522B;&#x5728;&#x4E8E; <code>handle_events/3</code> &#x51FD;&#x6570;&#x7684;&#x8FD4;&#x56DE;&#x503C;.  &#x5728;&#x751F;&#x4EA7;&#x8005;-&#x6D88;&#x8D39;&#x8005;&#x4E2D;, &#x8FD4;&#x56DE;&#x503C;&#x5143;&#x7EC4;&#x7684;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570; -- &#x8FD9;&#x91CC;&#x662F; <code>numbers</code> -- &#x5C06;&#x7528;&#x4E8E;&#x6EE1;&#x8DB3;&#x4E0B;&#x6E38;&#x6D88;&#x8D39;&#x8005;&#x7684;&#x9700;&#x6C42;.  &#x5728;&#x6D88;&#x8D39;&#x8005;&#x4E2D;, &#x8FD9;&#x4E2A;&#x503C;&#x4F1A;&#x88AB;&#x4E22;&#x5F03;.</p>
<h2 id="&#x6D88;&#x8D39;&#x8005;">&#x6D88;&#x8D39;&#x8005;</h2>
<p>&#x6700;&#x540E;&#x6765;&#x8BA9;&#x6211;&#x4EEC;&#x6765;&#x770B;&#x770B;&#x540C;&#x6837;&#x91CD;&#x8981;&#x7684;&#x6D88;&#x8D39;&#x8005;:</p>
<pre><code class="lang-shell">$ touch lib/genstage_example/consumer.ex
</code></pre>
<p>&#x7531;&#x4E8E;&#x6D88;&#x8D39;&#x8005;&#x548C;&#x751F;&#x4EA7;&#x8005;-&#x6D88;&#x8D39;&#x8005;&#x592A;&#x76F8;&#x4F3C;&#x4E86;, &#x6240;&#x4EE5;&#x4EE3;&#x7801;&#x770B;&#x8D77;&#x6765;&#x6CA1;&#x6709;&#x4EC0;&#x4E48;&#x533A;&#x522B;:</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">GenstageExample</span></span>.Consumer <span class="hljs-keyword">do</span>
  <span class="hljs-keyword">use</span> GenStage

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">start_link</span></span> <span class="hljs-keyword">do</span>
    GenStage.start_link(__MODULE_<span class="hljs-number">_</span>, <span class="hljs-symbol">:state_doesnt_matter</span>)
  <span class="hljs-keyword">end</span>

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">init</span></span>(state) <span class="hljs-keyword">do</span>
    {<span class="hljs-symbol">:consumer</span>, state, <span class="hljs-symbol">subscribe_to:</span> [GenstageExample.ProducerConsumer]}
  <span class="hljs-keyword">end</span>

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">handle_events</span></span>(events, _from, state) <span class="hljs-keyword">do</span>
    <span class="hljs-keyword">for</span> event &lt;- events <span class="hljs-keyword">do</span>
      IO.inspect({<span class="hljs-keyword">self</span>(), event, state})
    <span class="hljs-keyword">end</span>

    <span class="hljs-comment"># As a consumer we never emit events</span>
    {<span class="hljs-symbol">:noreply</span>, [], state}
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<p>&#x6B63;&#x5982;&#x4E4B;&#x524D;&#x63D0;&#x5230;&#x7684;, &#x6211;&#x4EEC;&#x7684;&#x6D88;&#x8D39;&#x8005;&#x4E0D;&#x4F1A;&#x751F;&#x4EA7;&#x4E8B;&#x4EF6;, &#x6240;&#x4EE5;&#x5143;&#x7EC4;&#x7684;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x4F1A;&#x88AB;&#x629B;&#x5F03;.</p>
<h2 id="&#x628A;&#x5B83;&#x4EEC;&#x7ED3;&#x5408;&#x8D77;&#x6765;">&#x628A;&#x5B83;&#x4EEC;&#x7ED3;&#x5408;&#x8D77;&#x6765;</h2>
<p>&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x6709;&#x4E86;&#x751F;&#x4EA7;&#x8005;, &#x751F;&#x4EA7;&#x8005;-&#x6D88;&#x8D39;&#x8005;&#x548C;&#x6D88;&#x8D39;&#x8005;, &#x6211;&#x4EEC;&#x5DF2;&#x7ECF;&#x51C6;&#x5907;&#x597D;&#x628A;&#x6240;&#x6709;&#x4E1C;&#x897F;&#x6346;&#x7ED1;&#x5728;&#x4E00;&#x8D77;&#x4E86;.</p>
<p>&#x9996;&#x5148;, &#x6253;&#x5F00; <code>lib/genstage_example/application.ex</code> &#x5E76;&#x6DFB;&#x52A0;&#x6211;&#x4EEC;&#x7684;&#x65B0;&#x8FDB;&#x7A0B;&#x5230;&#x76D1;&#x63A7;&#x6811;:</p>
<pre><code class="lang-elixir"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">start</span></span>(_type, _args) <span class="hljs-keyword">do</span>
  import Supervisor.Spec, <span class="hljs-symbol">warn:</span> <span class="hljs-keyword">false</span>

  children = [
    worker(GenstageExample.Producer, [<span class="hljs-number">0</span>]),
    worker(GenstageExample.ProducerConsumer, []),
    worker(GenstageExample.Consumer, [])
  ]

  opts = [<span class="hljs-symbol">strategy:</span> <span class="hljs-symbol">:one_for_one</span>, <span class="hljs-symbol">name:</span> GenstageExample.Supervisor]
  Supervisor.start_link(children, opts)
<span class="hljs-keyword">end</span>
</code></pre>
<p>&#x5982;&#x679C;&#x4E00;&#x5207;&#x6B63;&#x786E;, &#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x7684;&#x9879;&#x76EE;&#x5C31;&#x53EF;&#x4EE5;&#x8FD0;&#x884C;, &#x53EF;&#x4EE5;&#x770B;&#x5230;&#x5B83;&#x80FD;&#x591F;&#x5DE5;&#x4F5C;:</p>
<pre><code class="lang-shell">$ mix run --no-halt
{#PID&lt;0.109.0&gt;, 2, :state_doesnt_matter}
{#PID&lt;0.109.0&gt;, 4, :state_doesnt_matter}
{#PID&lt;0.109.0&gt;, 6, :state_doesnt_matter}
...
{#PID&lt;0.109.0&gt;, 229062, :state_doesnt_matter}
{#PID&lt;0.109.0&gt;, 229064, :state_doesnt_matter}
{#PID&lt;0.109.0&gt;, 229066, :state_doesnt_matter}
</code></pre>
<p>&#x6211;&#x4EEC;&#x505A;&#x5230;&#x4E86;!  &#x6B63;&#x5982;&#x6211;&#x4EEC;&#x9884;&#x671F;&#x7684;&#x90A3;&#x6837;, &#x7A0B;&#x5E8F;&#x53EA;&#x4F1A;&#x4EA7;&#x751F;&#x5076;&#x6570;, &#x800C;&#x4E14;&#x975E;&#x5E38; <strong>&#x5FEB;</strong>.</p>
<p>&#x8FD9;&#x6837;, &#x6211;&#x4EEC;&#x5C31;&#x6709;&#x4E86;&#x4E00;&#x6761;&#x5DE5;&#x4F5C;&#x6D41;.  &#x4E00;&#x4E2A;&#x751F;&#x4EA7;&#x8005;&#x4EA7;&#x751F;&#x6570;&#x5B57;, &#x4E00;&#x4E2A;&#x751F;&#x4EA7;&#x8005;-&#x6D88;&#x8D39;&#x8005;&#x8FC7;&#x6EE4;&#x6389;&#x5947;&#x6570;, &#x7136;&#x540E;&#x4E00;&#x4E2A;&#x6D88;&#x8D39;&#x8005;&#x663E;&#x793A;&#x6240;&#x6709;&#x8FD9;&#x4E9B;, &#x5E76;&#x8BA9;&#x7BA1;&#x9053;&#x6301;&#x7EED;&#x6D41;&#x52A8;.</p>
<h2 id="&#x591A;&#x4E2A;&#x751F;&#x4EA7;&#x8005;&#x6216;&#x6D88;&#x8D39;&#x8005;">&#x591A;&#x4E2A;&#x751F;&#x4EA7;&#x8005;&#x6216;&#x6D88;&#x8D39;&#x8005;</h2>
<p>&#x5728;&#x7B80;&#x4ECB;&#x91CC;, &#x6211;&#x4EEC;&#x6709;&#x63D0;&#x5230;&#x53EF;&#x4EE5;&#x540C;&#x65F6;&#x6709;&#x591A;&#x4E2A;&#x751F;&#x4EA7;&#x8005;&#x6216;&#x6D88;&#x8D39;&#x8005;. &#x8BA9;&#x6211;&#x4EEC;&#x6765;&#x770B;&#x770B;&#x662F;&#x600E;&#x4E48;&#x4E00;&#x56DE;&#x4E8B;.</p>
<p>&#x5982;&#x679C;&#x6211;&#x4EEC;&#x68C0;&#x67E5;&#x4E0A;&#x9762;&#x4F8B;&#x5B50;&#x91CC; <code>IO.inspect/1</code> &#x7684;&#x8F93;&#x51FA;, &#x4F1A;&#x53D1;&#x73B0;&#x6240;&#x6709;&#x7684;&#x4E8B;&#x4EF6;&#x90FD;&#x662F;&#x7531;&#x540C;&#x4E00;&#x4E2A;&#x8FDB;&#x7A0B;&#x6765;&#x5904;&#x7406;&#x7684;.  &#x8BA9;&#x6211;&#x4EEC;&#x4FEE;&#x6539; <code>lib/genstage_example/application.ex</code> &#x4EE5;&#x914D;&#x7F6E;&#x591A;&#x4E2A; worker:</p>
<pre><code class="lang-elixir">children = [
  worker(GenstageExample.Producer, [<span class="hljs-number">0</span>]),
  worker(GenstageExample.ProducerConsumer, []),
  worker(GenstageExample.Consumer, [], <span class="hljs-symbol">id:</span> <span class="hljs-number">1</span>),
  worker(GenstageExample.Consumer, [], <span class="hljs-symbol">id:</span> <span class="hljs-number">2</span>)
]
</code></pre>
<p>&#x73B0;&#x5728;, &#x6211;&#x4EEC;&#x6709;&#x4E86;&#x4E24;&#x4E2A;&#x6D88;&#x8D39;&#x8005;, &#x8BA9;&#x6211;&#x4EEC;&#x6765;&#x770B;&#x4E00;&#x4E0B;&#x73B0;&#x5728;&#x8FD0;&#x884C;&#x5E94;&#x7528;&#x7684;&#x7ED3;&#x679C;:</p>
<pre><code class="lang-shell">$ mix run --no-halt
{#PID&lt;0.120.0&gt;, 2, :state_doesnt_matter}
{#PID&lt;0.121.0&gt;, 4, :state_doesnt_matter}
{#PID&lt;0.120.0&gt;, 6, :state_doesnt_matter}
{#PID&lt;0.120.0&gt;, 8, :state_doesnt_matter}
...
{#PID&lt;0.120.0&gt;, 86478, :state_doesnt_matter}
{#PID&lt;0.121.0&gt;, 87338, :state_doesnt_matter}
{#PID&lt;0.120.0&gt;, 86480, :state_doesnt_matter}
{#PID&lt;0.120.0&gt;, 86482, :state_doesnt_matter}
</code></pre>
<p>&#x5982;&#x4F60;&#x6240;&#x89C1;, &#x73B0;&#x5728;&#x6709;&#x4E86;&#x591A;&#x4E2A; PID, &#x53EA;&#x9700;&#x8981;&#x7B80;&#x5355;&#x5730;&#x6DFB;&#x52A0;&#x4E00;&#x884C;&#x4EE3;&#x7801;&#x5E76;&#x6307;&#x5B9A;&#x6D88;&#x8D39;&#x8005;&#x7684; ID.</p>
<h2 id="&#x7528;&#x4F8B;">&#x7528;&#x4F8B;</h2>
<p>&#x73B0;&#x5728;, &#x6211;&#x4EEC;&#x5DF2;&#x7ECF;&#x4E86;&#x89E3;&#x4E86; GenStage, &#x5E76;&#x6784;&#x5EFA;&#x4E86;&#x6211;&#x4EEC;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x793A;&#x4F8B;&#x5E94;&#x7528;, &#x90A3;&#x4E48; GenStage &#x6709;&#x54EA;&#x4E9B; <strong>&#x771F;&#x5B9E;</strong> &#x7684;&#x7528;&#x4F8B;&#x5462;?</p>
<ul>
<li><p>&#x6570;&#x636E;&#x8F6C;&#x6362;&#x7BA1;&#x9053; &#x2014; &#x751F;&#x4EA7;&#x8005;&#x4E0D;&#x5FC5;&#x662F;&#x7B80;&#x5355;&#x7684;&#x6570;&#x5B57;&#x751F;&#x6210;&#x5668;. &#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4ECE;&#x6570;&#x636E;&#x5E93;&#x751A;&#x81F3;&#x5176;&#x4ED6;&#x6765;&#x6E90;(&#x5982; Apache&apos;s Kafka)&#x751F;&#x6210;&#x4E8B;&#x4EF6;.  &#x518D;&#x52A0;&#x4E0A;&#x751F;&#x4EA7;&#x8005;-&#x6D88;&#x8D39;&#x8005;&#x548C;&#x6D88;&#x8D39;&#x8005;, &#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5728;&#x5B83;&#x4EEC;&#x53EF;&#x7528;&#x7684;&#x65F6;&#x5019;&#x505A;&#x5904;&#x7406;, &#x6392;&#x5E8F;, &#x5206;&#x7C7B;&#x4EE5;&#x53CA;&#x6307;&#x6807;&#x5B58;&#x50A8;.</p>
</li>
<li><p>&#x5DE5;&#x4F5C;&#x961F;&#x5217; &#x2014; &#x56E0;&#x4E3A;&#x4E8B;&#x4EF6;&#x53EF;&#x4EE5;&#x662F;&#x4EFB;&#x4F55;&#x4E1C;&#x897F;, &#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x751F;&#x4EA7;&#x7531;&#x4E00;&#x7CFB;&#x5217;&#x6D88;&#x8D39;&#x8005;&#x6765;&#x5904;&#x7406;&#x7684;&#x5355;&#x4F4D;&#x5DE5;&#x4F5C;.</p>
</li>
<li><p>&#x4E8B;&#x4EF6;&#x5904;&#x7406; &#x2014; &#x7C7B;&#x4F3C;&#x4E8E;&#x6570;&#x636E;&#x7BA1;&#x9053;, &#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5BF9;&#x6E90;&#x4EA7;&#x751F;&#x7684;&#x5B9E;&#x65F6;&#x4E8B;&#x4EF6;&#x8FDB;&#x884C;&#x63A5;&#x6536;, &#x5904;&#x7406;, &#x6392;&#x5E8F;, &#x4EE5;&#x53CA;&#x505A;&#x51FA;&#x884C;&#x52A8;.</p>
</li>
</ul>
<p>&#x8FD9;&#x4E9B;&#x53EA;&#x662F; GenStage &#x7684; <strong>&#x4E00;&#x5C0F;&#x90E8;&#x5206;</strong> &#x53EF;&#x80FD;&#x6027;.</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="behaviours.html" class="navigation navigation-prev " aria-label="Previous page: 行为">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="protocols.html" class="navigation navigation-next " aria-label="Next page: 协议">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"version":"1.0.2","title":"GenStage","level":"2.12","depth":1,"next":{"title":"协议","level":"2.13","depth":1,"path":"lessons/advanced/protocols.md","ref":"lessons/advanced/protocols.md","articles":[]},"previous":{"title":"行为","level":"2.11","depth":1,"path":"lessons/advanced/behaviours.md","ref":"lessons/advanced/behaviours.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"lessons/advanced/gen-stage.md","mtime":"2019-11-05T02:25:51.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-11-05T03:01:22.004Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

